package com.jboost.hyk.common.constant;

import com.baomidou.mybatisplus.annotation.EnumValue;
import com.fasterxml.jackson.annotation.JsonValue;
import com.jboost.common.constant.CommonConstant;
import com.jboost.common.constant.EnumInterface;

/**
 *@ClassName
 *@Description 订单状态
 *@Author cxn
 *@Date 2022-10-11
 *@Version
 **/
public enum OrderStatusEnum implements EnumInterface {
//  状态：待支付-unpaid；退款中-refunding；已完成-completed；已关闭-closed；
     UNPAID("unpaid", "待支付"),
     REFUNDING("refunding", "退款中"),
    COMPLETED("completed", "已完成"),
    CLOSED("closed", "已关闭"),
    REFUNDED("refunded", "已退款");

    OrderStatusEnum(String code, String desc) {
        this.code = code;
        this.desc = desc;
    }

    @EnumValue
    @JsonValue    //标记响应json值
    private final String code;
    private final String desc;

    public String getCode() {
        return code;
    }

    public String getDesc() {
        return desc;
    }
    public static OrderStatusEnum getByCode(String code) {
        OrderStatusEnum[] enums = OrderStatusEnum.values();
        for (int i = 0; i < enums.length; i++) {
            if(enums[i].code.equals(code)){
                return enums[i];
            }
        }
        return null;
    }
    public static String getDescByCode(String code) {
        OrderStatusEnum status = OrderStatusEnum.getByCode(code);
        if(null == status){
            return CommonConstant.UNDIFIND_DEFALUT;
        }
        return status.getDesc();
    }

    @Override
    public String desc() {
        return this.desc;
    }

    @Override
    public Integer value() {
        return null;
    }

    @Override
    public String code() {
        return this.code;
    }

}
